import 'package:dio/dio.dart';
import 'dart:async';
import 'dart:io';
import '../config/service_urls.dart';

// 首页接口
Future getHomePageContent() async{
  try {
   print('获取首页数据开始...'); 
   Response response;
   Dio dio = new Dio();
   dio.options.contentType = ContentType.parse("application/x-www-form-urlencoded");
   var formData = {'lon':'115.02932','lat':'35.76189'};
   response = await dio.post(servicePath['homePageContext'], data: formData);
   if(response.statusCode == 200) {
     return response.data;
   } else {
     throw Exception('后端接口返回异常......');
   }
  } catch (e) {
    return print('ERROR:=====>$e');
  }
}

// 通用接口
Future request(url, {formData}) async{
  try {
   print('数据请求开始...'); 
   Response response;
   Dio dio = new Dio();
   dio.options.contentType = ContentType.parse("application/x-www-form-urlencoded");
   if(formData!=null) {
    response = await dio.post(servicePath[url], data: formData);
   } else {
    response = await dio.post(servicePath[url]);
   }
   if(response.statusCode == 200) {
     return response.data;
   } else {
     throw Exception('后端接口返回异常......');
   }
  } catch (e) {
    return print('ERROR:=====>$e');
  }
}